package com.chain.BrotherExchange.ui.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.chain.BrotherExchange.R;
import com.chain.BrotherExchange.data.model.OrderRecord;

import java.util.List;

public class VisualQuotationAdapter extends RecyclerView.Adapter<VisualQuotationAdapter.ViewHolder> {

    private List<OrderRecord> mOrderRecordList;

    @NonNull
    @Override
    public VisualQuotationAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ViewHolder(LayoutInflater.from(viewGroup.getContext())
                .inflate(R.layout.item_visual_quotation, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull VisualQuotationAdapter.ViewHolder holder, int i) {
        OrderRecord orderRecord = mOrderRecordList.get(i);
        holder.mBuyNoText.setText(String.valueOf(i + 1));
        holder.mSaleNoText.setText(String.valueOf(i + 1));
        holder.mBuyNumberText.setText(orderRecord.getSaleNumber());
        holder.mBuyPriceText.setText(orderRecord.getSalePrice());
        holder.mSaleNumberText.setText(orderRecord.getBuyNumber());
        holder.mSalePriceText.setText(orderRecord.getBuyPrice());
    }

    public void setData(List<OrderRecord> list) {
        this.mOrderRecordList = list;
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return mOrderRecordList != null ? mOrderRecordList.size() : 0;
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView mBuyNumberText;
        private final TextView mBuyPriceText;
        private final TextView mSalePriceText;
        private final TextView mSaleNumberText;
        private final TextView mBuyNoText;
        private final TextView mSaleNoText;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            mBuyNumberText = itemView.findViewById(R.id.buy_number_text);
            mBuyPriceText = itemView.findViewById(R.id.buy_price_text);
            mSalePriceText = itemView.findViewById(R.id.sale_price_text);
            mSaleNumberText = itemView.findViewById(R.id.sale_number_text);
            mBuyNoText = itemView.findViewById(R.id.buy_no_text);
            mSaleNoText = itemView.findViewById(R.id.sale_on_text);
        }
    }
}
